/*
 *  Created at 2011-01-09 14:30 GMT-03:00
 *  Author: Victor Williams Stafusa da Silva
 *  JSmartUnit
 */
package org.jsmartunit.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Arrays;
import java.util.List;

import org.jsmartunit.model.MethodRunnerFactory;
import org.jsmartunit.model.TestRunner;
import org.jsmartunit.model.TestRunnerFactory;

import org.junit.runners.model.InitializationError;

/**
 * @author Victor Williams Stafusa da Silva
 */
@Documented
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
@Retention(RetentionPolicy.RUNTIME)
@RunMethodWith(StringParameterMethodRunner.class)
public @interface StringParams {
    public String[] value();
}

/**
 * @author Victor Williams Stafusa da Silva
 */
class StringParameterMethodRunner implements MethodRunnerFactory {

    @Override
    public List<TestRunner> create(TestRunnerFactory invoke) throws InitializationError {
        if (invoke == null) throw new IllegalArgumentException();

        StringParams ip = invoke.getAnnotation(StringParams.class);
        if (ip == null) throw new IllegalArgumentException();

        return invoke.createSingleArgRunners(Arrays.asList(ip.value()), null);
    }
}